package cn.itcast.service;

import cn.itcast.mapper.UserMapper;
import cn.itcast.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Random;

@Service
public class UserService {
    @Autowired
    private UserMapper userMapper;

//    public User queryById(Long id) {
//        return this.userMapper.selectByPrimaryKey(id);
//    }


    public User queryById(Long id) throws InterruptedException {
        // 为了演示超时现象，我们在这里然线程休眠,时间随机 0~2000毫秒
        int time = new Random().nextInt(2000);
        System.out.println(id+"=="+time);
        Thread.sleep(time);
        return this.userMapper.selectByPrimaryKey(id);
    }
}